index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { PermissionAction } from '@supabase/shared-types/out/constants'
  2. import { useParams } from 'common'
  3. import { useMemo } from 'react'
  4. import { Separator } from 'ui'
  5. import {
  6. ApiKeysCreateCallout,
  7. ApiKeysFeedbackBanner,
  8. } from '@/components/interfaces/APIKeys/ApiKeysIllustrations'
  9. import { PublishableAPIKeys } from '@/components/interfaces/APIKeys/PublishableAPIKeys'
  10. import { SecretAPIKeys } from '@/components/interfaces/APIKeys/SecretAPIKeys'
  11. import ApiKeysLayout from '@/components/layouts/APIKeys/APIKeysLayout'
  12. import { DefaultLayout } from '@/components/layouts/DefaultLayout'
  13. import SettingsLayout from '@/components/layouts/ProjectSettingsLayout/SettingsLayout'
  14. import { DisableInteraction } from '@/components/ui/DisableInteraction'
  15. import { useAPIKeysQuery } from '@/data/api-keys/api-keys-query'
  16. import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
  17. import type { NextPageWithLayout } from '@/types'
  18. const ApiKeysNewPage: NextPageWithLayout = () => {
  19. const { ref: projectRef } = useParams()
  20. const { can: canReadAPIKeys } = useAsyncCheckPermissions(PermissionAction.SECRETS_READ, '*')
  21. const { data: apiKeysData = [] } = useAPIKeysQuery(
  22. {
  23. projectRef,
  24. reveal: false,
  25. },
  26. { enabled: canReadAPIKeys }
  27. )
  28. const newApiKeys = useMemo(
  29. () => apiKeysData.filter(({ type }) => type === 'publishable' || type === 'secret'),
  30. [apiKeysData]
  31. )
  32. const hasNewApiKeys = newApiKeys.length > 0
  33. return (
  34. <>
  35. {canReadAPIKeys && !hasNewApiKeys && <ApiKeysCreateCallout />}
  36. {hasNewApiKeys && <ApiKeysFeedbackBanner />}
  37. <DisableInteraction disabled={!hasNewApiKeys} className="flex flex-col gap-8">
  38. <PublishableAPIKeys />
  39. <Separator />
  40. <SecretAPIKeys />
  41. </DisableInteraction>
  42. </>
  43. )
  44. }
  45. ApiKeysNewPage.getLayout = (page) => (
  46. <DefaultLayout>
  47. <SettingsLayout title="api keys">
  48. <ApiKeysLayout>{page}</ApiKeysLayout>
  49. </SettingsLayout>
  50. </DefaultLayout>
  51. )
  52. export default ApiKeysNewPage